
import { defineStore } from "pinia";
import { getHomeData } from "../api/api";
import { ref } from "vue";

export const useShopCarStore = defineStore("shopcar_data", () => {
    let list = ref([]); //选中商品的集合
    let initList = (arr: any) => {
        list.value = arr;
    }
    return { list, initList };
})

export const useDataStore = defineStore('all_data', {
    state: () => {
        return {
            carNum: 0,
            homeData: null,
        }
    },
    getters: {
        newCount(state) {
            return state.carNum * 10;
        }
    },
    actions: {
        setCarNum(payload: number) {
            this.carNum = payload
        },
        async getHomeDataAsync() {
            let res: any = await getHomeData({
            })
            if (res.status == 200) {
                this.homeData = res.data.pageData.items;
            }
        }
    }
})